{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import re\n",
    "import os\n",
    "\n",
    "all_data = []\n",
    "with open(\"devset.json\") as f1:\n",
    "    for line in f1.readlines():\n",
    "        data = json.loads(line)\n",
    "        all_data.append(data)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['shape_params', 'decoration', 'notes', 'rotations', 'filename', 'states', 'images', 'side_length'])\n",
      "['blue', 'green', 'cyan', 'magenta', 'yellow', 'red']\n",
      "Ang.spaceship.w\n",
      "18\n",
      "['Move Mercedes Benz one space right.', 'Place Mercedes Benz one space above Twitter.', \"We'll create a square. With Twitter in the bottom left, place Mercedes Benz in the top right, touching each other\", \"Take the block with the Mercedes Benz logo and move it rightward until it is lined up with the block with the Twitter logo. The two should be on the same level, and their right and left edges should align, while the Mercedes Benz's lower edge touches the Twitter's top edge.\", 'Move the Mercedes Benz box to the right so that it lines up with the Twitter box.', 'Place the Mercedes Benz block right behind the Twitter block.', 'Move mercedes benz above twitter', 'Mercedes Benz winds up above and connected to twitter', 'Mercedes Benz will move right until it is above twitter']\n",
      "19\n",
      "[[0.0, 0.0, 0.0, 1.0], [-4e-05, -0.00041, 0.00047, 1.0], [0.0, 0.0, 0.0, 1.0], [-1e-05, -0.00046, 0.00018, 1.0], [0.0, 0.0, 0.0, 1.0], [-4e-05, -0.00041, 0.00055, 1.0], [1e-05, -1e-05, 0.0, 1.0], [0.0, 0.0, 0.0, 1.0], [1e-05, -2e-05, 0.0, 1.0], [1e-05, 0.0, 0.0, 1.0], [0.0, 0.0, 0.0, 1.0], [0.0, 0.0, 0.0, 1.0], [0.0, 0.0, 0.0, 1.0], [0.0, 0.0, 0.0, 1.0], [0.0, 0.0, 0.0, 1.0], [-4e-05, -0.00041, 0.00045, 1.0], [1e-05, -1e-05, 0.0, 1.0], [2e-05, -2e-05, -1e-05, 1.0], [-5e-05, 7e-05, 4e-05, 1.0]]\n",
      "19\n",
      "[[-0.69366, 0.07573, -0.31686], [-0.27073, 0.07135, -0.08443], [0.1, 0.07573, 0.0], [0.59369, 0.07197, -0.44849], [0.7, 0.07573, 0.0], [-0.67946, 0.07121, 0.30005], [-0.56999, 0.07395, -0.60961], [0.24539, 0.07573, -0.28416], [-0.26156, 0.074, -0.56749], [0.67916, 0.07383, -0.84162], [-0.5, 0.07573, 0.6], [-0.12445, 0.07573, 0.3193], [0.15002, 0.07573, 0.34976], [0.4, 0.07573, 0.6], [0.84047, 0.07573, 0.71606], [-0.71752, 0.07139, 0.73615], [-0.77783, 0.07463, -0.86557], [0.3921, 0.07648, 0.15108], [-0.07322, 0.06953, -0.7315]]\n"
     ]
    }
   ],
   "source": [
    "first = all_data[0]\n",
    "print(first.keys())\n",
    "print(first[\"shape_params\"])\n",
    "print(first[\"filename\"])\n",
    "print(len(first[\"notes\"]))\n",
    "print(first[\"notes\"][0][\"notes\"])\n",
    "print(len(first[\"rotations\"]))\n",
    "print(first[\"rotations\"][0])\n",
    "print(len(first[\"states\"]))\n",
    "print(first[\"states\"][0])\n",
    "\n",
    "# second = all_data[1]\n",
    "# print(second.keys())\n",
    "# print(len(second[\"notes\"]))\n",
    "# print(second[\"notes\"][0][\"notes\"])\n",
    "# print(len(second[\"rotations\"]))\n",
    "# print(second[\"rotations\"][0])\n",
    "# print(len(second[\"states\"]))\n",
    "# print(second[\"states\"][0])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-0.82511\n",
      "0.67352\n",
      "[-0.26156, 0.074, -0.56749]\n",
      "[-0.0742, 0.07401, -0.5804]\n"
     ]
    }
   ],
   "source": [
    "for datapoint in all_data:\n",
    "    states_list = datapoint[\"states\"]\n",
    "    flat_states = []\n",
    "    for states in states_list:\n",
    "        for tup in states:\n",
    "            for i in tup:\n",
    "                flat_states.append(i)\n",
    "print(min(flat_states))\n",
    "print(max(flat_states))\n",
    "\n",
    "\n",
    "first = all_data[0]\n",
    "og_mercedes = first[\"states\"][0][8]\n",
    "next_mercedes = first[\"states\"][1][8]\n",
    "print(og_mercedes)\n",
    "print(next_mercedes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# BLOCKS WORLD DATA FORMAT \n",
    "# PER LINE, EACH LINE IS AN EXAMPLE\n",
    "\n",
    "{'shape_params': List[str], # parameters for the shape colors?  \n",
    " 'decoration': str, # type of decoration \n",
    " 'notes': List[str], # list of n instructions  \n",
    " 'rotations': List[List]], # list of n+1 rotations (4-tuple) with extra for start state \n",
    " 'filename': str, # filename of the example \n",
    " 'states': List[List]], # n+1 x,y,z positions with extra for start state \n",
    " 'images': List[str], # filenames of n+1 images \n",
    " 'side_length': float, # length of the side of the block \n",
    "}\n",
    "\n",
    "# QUESTIONS\n",
    "# 1. what is each position in the rotation tuple? A: quaternions \n",
    "# 2. What is the origin for x,y,z? A: Since it has positive and negative for x and z, must be in the center. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# SIMULATOR DATA FORMAT \n",
    "# space-separated \n",
    "# 0: obj_id\n",
    "# 1: mesh color: r\n",
    "# 2: mesh color: g\n",
    "# 3: mesh color: b\n",
    "# 4: pos: x\n",
    "# 5: pos: y\n",
    "# 6: pos: z\n",
    "# 7: rot: theta1\n",
    "# 8: rot: theta2\n",
    "# 9: rot: theta3\n",
    "\n",
    "# Questions\n",
    "# 1. what are the angles in the rotation?\n",
    "# 2. how to convert from quaternions to angles? "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
